/**
 * Copyright (c) 2013-2016, Jieven. All rights reserved.
 *
 * Licensed under the GPL license: http://www.gnu.org/licenses/gpl.txt
 * To use it on other terms please contact us at 1623736450@qq.com
 */
package com.jobsys.model;

import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jobsys.utils.xx;

/**
 * 用户表
 *
 * @author
 * @date
 */
public class MUserinfo extends BaseModel<MUserinfo> {

	private static final long serialVersionUID = 4254060861819273244L;

	public static MUserinfo dao = new MUserinfo();

	public List<MUserinfo> findAll() {
		return this.find("select * from userinfo");
	}

	public List<MUserinfo> findAll(int page, int pagesize) {
		return this.find("select * from userinfo limit ?,?", (page - 1) * pagesize, pagesize);
	}

	public int Count() {
		MUserinfo model = MUserinfo.dao.findFirst("select count(*) as count from userinfo");
		int count = model.getLong("count").intValue();

		return count;
	}

	public MUserinfo findByUserID(String userid) {
		return this.findFirst("select * from userinfo where userID = ? and isDelete=0", userid);
	}

	public int updateState(int id, String userID, String nickname, String pwd, int right, int isdelete) {
		return Db.use(xx.DS_JOB).update(
				"update userinfo set userID=?,nickname = ?,pwd=?,rightx=?,isDelete=? where id = ?", userID, nickname,
				pwd, right, isdelete, id);
	}

	public int deleteUser(String id, String userID) {
		if (null != id && "" != id) {
			return Db.use(xx.DS_JOB).update("update userinfo set isDelete = 1 where id = ?", id);
		} else {
			return Db.use(xx.DS_JOB).update("update userinfo set isDelete = 1 where userID = ?", userID);
		}
	}
}